package ua.tcrs.tabula.log;

public class SimpleLogger implements Logger {
	public void trace( Object... msgs ) { doLog( "TRACE", msgs ); }
	public void debug( Object... msgs ) { doLog( "DEBUG", msgs ); }
	public void info( Object... msgs ) { doLog( "INFO ", msgs ); }
	public void warn( Object... msgs ) { doLog( "WARN ", msgs ); }
	public void error( Object... msgs ) { doLog( "ERROR", msgs ); }
	
	private synchronized void doLog( String level, Object... msgs ) {
		System.err.print( level );
		System.err.print( ' ' );
		Throwable t = null;
		for ( Object msg: msgs ) {
			if ( msg instanceof Throwable ) {
				t = (Throwable)msg;
			} else {
				System.err.print( msg );
			}
		}
		System.err.println();
		if ( t != null ) {
			t.printStackTrace( System.err );
		}
	}
}
